﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinanceTool.Entities;

namespace FinanceTool.Components
{
    internal abstract class SourceFileReader : ISourceFileReader
    {
        private List<Transaction> _transactionList;
        public List<Transaction> TransactionList
        {
            get
            {
                if (_transactionList == null) _transactionList = new List<Transaction>();
                return _transactionList;
            }
        }

        public abstract bool HasFirstLine
        {
            get;
        }

        public abstract List<Transaction> ReadTransactions();   

        public List<Transaction> FilterByDescription(string description)
        {
            var retVal = (from transaction in TransactionList
                          where transaction.NameOrDescription.Contains(description)
                          select transaction).ToList();

            return retVal;
        }


        public List<Transaction> FilterByDate(DateTime fromDate, DateTime toDate)
        {
            var retVal = (from transaction in TransactionList
                          where transaction.Date >= fromDate && transaction.Date <= toDate
                          select transaction).ToList();

            return retVal;
        }
    }
}
